package com.cloud.qualitycontrol.service.impl;

import com.cloud.qualitycontrol.dao.FileFolderRepository;
import com.cloud.qualitycontrol.model.FileFolder;
import com.cloud.qualitycontrol.service.FolderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

@Service
public class FolderServiceImpl implements FolderService {

    @Autowired
    private FileFolderRepository fileFolderRepository;

    @Override
    public FileFolder addFolder(final FileFolder fileFolder) {
        return fileFolderRepository.saveAndFlush(fileFolder);
    }

    @Override
    public List<FileFolder> selectAll() {
        return fileFolderRepository.findAll();
    }

    @Override
    public FileFolder selectById(final String id) {
        return fileFolderRepository.getOne(id);
    }

    @Override
    public Set<FileFolder> selectByQualityId(String qualityId) {
        return fileFolderRepository.getByQualityId(qualityId);
    }

    @Override
    public void deleteById(final String id) {
        fileFolderRepository.delete(id);
    }

    @Override
    public FileFolder updateFolder(final FileFolder fileFolder) {
        return fileFolderRepository.saveAndFlush(fileFolder);
    }
}
